/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AST;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Eddy
 */
public class Errores {
    static LinkedList<String> Errors;
    public static void IniciarErrores()
    {
        if(Errors==null)
        {
        Errors=new LinkedList();
        }
        
    }
    
    public static boolean InsertarError(int linea,int col,String Error)
     {
        boolean res=true;
        IniciarErrores();
         String a = "<td>" + Integer.toString(linea)+" "+Integer.toString(col) + "</td>" + "\n";
         String b = "<td>" + Error + "</td>" + "\n";
         
         String c="<tr>"+a+b+"</tr>"+"\n";
         Errors.add(c);
        return res;
    }
    
    public static boolean ImprimirErrores(String NombreErrores)
    {
        boolean res=true;
        IniciarErrores();
        FileWriter fw = null;
    try
    {
      String Encabezado = "</Head>\n <Title>Errores</Title> \n</Head>\n";
      String Salida = "";
      int i;
      for ( i= 0; i < Errors.size(); i++)
      {
        Salida = Salida + (String)Errors.get(i);
      }
      Salida = "<table border=\"1\">\n" + Salida + "\n" + "</table>";
      Salida = "<HTML>\n" + Encabezado + Salida + "</HTML>" + "\n";

      fw = new FileWriter(NombreErrores);

      BufferedWriter bw = new BufferedWriter(fw);

      for (i = 0; i < Salida.length(); i++)
      {
        if (Salida.charAt(i) != '\n')
        {
          bw.write(Salida.charAt(i));
        }
        else
        {
          bw.newLine();
        }
      }

      bw.close();
      fw.close();
    }
    catch (IOException ex)
    {
      Logger.getLogger(Errores.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      try {
        fw.close();
      } catch (IOException ex) {
        Logger.getLogger(Errores.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
     return res;
    }
    
}
